<?php

class Model_user extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->load->database();
        $this->load->helper('text');
    }

    function get_user_trip_detail($str_id="") {        
        if($str_id == ''){
            return FALSE;
        }
        $sql = "SELECT trip.userId,trip.status, trip.id as tripId, trip.source_label, trip.destination_label,
                        trip.notes, trip.via, trip.departTime, trip.priceInRupiah, trip.priceInPoint,
                        trip.status,
                        user.id, user.name, user.avatar, user.gender, user.isPremium,
                        userprofile.idUser, userprofile.bio, userprofile.rate, userprofile.deliverCounter
                from trip, user, userprofile
                where trip.id = ? and trip.userId = user.id and userprofile.idUser = trip.userId";
        $query = $this->db->query($sql,$str_id);
        if($query->num_rows() == 1){ 
            $value = $query->row();
            return $value;
        } else {
            return FALSE;
        }
    }

    function get_riwayat_trip($str_id="") {    

        if($str_id == ''){
            return FALSE;
        }   
        $sql = "SELECT transaction.providerId, transaction.id, transaction.idTrip                       
                from transaction
                where transaction.providerId = ?";
        $query = $this->db->query($sql,$str_id);        

        if ($query->num_rows() > 0) {
            foreach ($query->result() as $value) {
                $a[] = $value;
            }
            return $a;
        } else {
            return FALSE;
        }
    }

    function get_providerId($str_id=""){
        if($str_id == ''){
            return FALSE;
        } 
        $sql = "SELECT trip.id, trip.userId, user.id
                from trip,user
                where trip.id = ? and trip.userId = user.id";
        $query = $this->db->query($sql,$str_id);
        if($query->num_rows() == 1){ 
            $value = $query->row();
            return $value;
        } else {
            return FALSE;
        }
    }

    function get_trip_detail($trip_id=""){
        if($trip_id == ''){
            return FALSE;
        } 
        $sql = "SELECT *
                from trip,user,transaction
                where trip.id = ? and transaction.idTrip = ? and transaction.userId = user.id";
        $query = $this->db->query($sql,array($trip_id,$trip_id));
        if($query->num_rows() == 1){ 
            $value = $query->row();
            return $value;
        } else {
            return FALSE;
        }
    }
}

?>